package ar.edu.unicen.exa.isistan.archassis.diff;

import java.util.ArrayList;
import java.util.List;

import ar.edu.unicen.exa.isistan.archassis.actions.ClassAction;
import ar.edu.unicen.exa.isistan.archassis.actions.IAction;
import ar.edu.unicen.exa.isistan.archassis.ia.api.db.JavaClass;
import ar.edu.unicen.exa.isistan.archassis.metadata.ClassResolver;

public class LastVersionDiffStrategy implements IDiffStrategy {

	public LastVersionDiffStrategy() {	}

	@Override
	public List<JavaClass> getJavaClassList(List<IAction> actions, ClassResolver classResolver) {
		
		List<JavaClass> result = new ArrayList<JavaClass>();
		for (IAction action : actions) {
			if (! action.getClass().getCanonicalName().equals(ClassAction.class.getCanonicalName())) {
				//no es una accion de clase creada.
				continue;
			}
			ClassAction classAction = (ClassAction)action;
			JavaClass javaClass = classResolver.getClassMetadata(classAction.getAbsoluteClassName());
			if (javaClass == null) {
				System.err.println("No se pudo obtener la clase " + classAction.getAbsoluteClassName());
			} else {
				result.add(javaClass);
			}
		}
		return result;
	}

}
